package co.edu.unal.bioingenium.kbmed.text.filter;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.HashSet;
import java.util.Set;


/*
 * 
 * */
/**
 *@author Alejandro Riveros Cruz 
 *@version StopWordFilter.java,v 1 2008/20/03  
 * */
public class StopWordFilter {

    /**
     *
     */
    private Set<String> stopWords;

    /**
     * @param:
     * @return:
     * @param stopWordFile 
     */
    public StopWordFilter(String stopWordFile) {
        stopWords = new HashSet<String>();
        loadStopWords(stopWordFile);
    }

    /**
     * @param:
     * @return:
     * @param stopWordFile 
     */
    private void loadStopWords(String stopWordFile) {
        File file;
        FileReader freader;
        BufferedReader bufreader;
        String line;
        try {
            file = new File(stopWordFile);
            freader = new FileReader(file);
            bufreader = new BufferedReader(freader);
            while ((line = bufreader.readLine()) != null) {
                stopWords.add(line.toLowerCase().trim());
            }
            bufreader.close();
        } catch (java.io.FileNotFoundException e1) {
            System.out.println("The file of stopWords \"" + stopWordFile + "\" don't exist");
        } catch (java.io.IOException e2) {
            System.out.println("Error reading stopWords file");
        }
    }

    /**
     * 
     * @param s
     * @return
     */
    public boolean isStopWord(String s) {
        if (stopWords.contains(s.toLowerCase())) {
            return true;
        }
        return false;
    }
}
